//
//  CinemaViewController.m
//  第六组电影项目
//
//  Created by 6-1 on 14-7-3.
//  Copyright (c) 2014年 www.skedu.com.cn北京尚德智远科技有限公司. All rights reserved.
//

#import "CinemaViewController.h"
#import "WXNetworkService.h"
#import "CinemaModel.h"
#import "CinemaCell.h"
#import "CommentViewController.h"
#import "MainViewController.h"

#define kRowHeight 100

@interface CinemaViewController ()
-(void)requestData;
-(void)refreshUI;
@end

@implementation CinemaViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
        self.title=@"影院";
    }
    return self;
}

-(void)loadView
{
    UIView *view=[[UIView alloc]initWithFrame:[UIScreen mainScreen].applicationFrame];
    self.view=view;
    cinemaTableView=[[UITableView alloc]initWithFrame:CGRectMake(0, 0, kDeviceWidth, kDeviceHeight-20-44-49)];
    cinemaTableView.dataSource=self;
    cinemaTableView.delegate=self;
    cinemaTableView.hidden=YES;
    cinemaTableView.rowHeight=kRowHeight;
    [self.view addSubview:cinemaTableView];
}
- (void)viewDidLoad
{
    [super viewDidLoad];
    [self requestData];
	// Do any additional setup after loading the view.
}
-(void)requestData
{
    NSArray *data=[WXNetworkService cinemaData];
    cinemaArray=[[NSMutableArray alloc]initWithCapacity:data.count];
    for (id dic in data)
    {
        CinemaModel *cinemaModel=[[CinemaModel alloc]initWithContent:dic];
        [cinemaArray addObject:cinemaModel];
    }
    [self refreshUI];
}
-(void)refreshUI
{
    cinemaTableView.hidden=NO;
    [cinemaTableView reloadData];
}
- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [cinemaArray count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *identifier=@"cell";
    CinemaCell *cell=[tableView dequeueReusableCellWithIdentifier:identifier];
    if (cell==nil)
    {
        cell=[[CinemaCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
    }
    cell.cinemaModel=cinemaArray[indexPath.row];
    return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    CommentViewController *comment=[[CommentViewController alloc]init];
    
    [self.navigationController pushViewController:comment animated:YES];
    
}
-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    self.tabBarController.tabBar.hidden = NO;
}
                              

@end
